﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;
using System.Data;

namespace HY.WEB.SA
{
    public partial class jobs_add : PageBase
    {
        public string whe = "", stype = "";
        public string us, um, bh;
        public string tab = "comp_job";
      
        protected void Page_Load(object sender, EventArgs e)
        {
           
            us = Session["ID"].ToString();
            bh = Session["bh"].ToString();
            um = Session["user"].ToString();
            //whe = " cbh in (select cbh from company_fav where sbh='" + bh + "')";

            if (!IsPostBack)
            {
                if (!String.IsNullOrEmpty(Request["stype"]))
                {
                     hidstype.Text = Request["sid"].Trim();                
                }
                if (!String.IsNullOrEmpty(Request["cbh"]))
                {
                    hidcomp.Text = Request["cbh"].Trim();
                } 

                fill();
            }

       
        }
 
     void   fill()
      {
           
          //公司分类
           DataTable e = BLL.Bllbase.get_table("[company]");
            ddlcompany.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlcompany.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["cname"].ToString().Trim(), e.Rows[i]["cbh"].ToString().Trim()));
            }
            ddlcompany.DataBind();

            if (hidcomp.Text != "")     //最公司      
              ddlcompany.SelectedIndex = ddlcompany.Items.IndexOf(ddlcompany.Items.FindByValue(hidcomp.Text));


         
        
    
            //岗位分类
            e = BLL.Bllbase.get_table("[pub_cate]");
          //  e = BLL.Bllbase.get_table("[pub_cate_sub]", " right(rtrim(scode)='00'");
             ddlgw.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlgw.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["svalue"].ToString().Trim(), e.Rows[i]["scode"].ToString().Trim()));
            }
            ddlgw.DataBind();

            ddlgw.SelectedIndex = ddlgw.Items.IndexOf(ddlgw.Items.FindByValue("3700"));
            ddlgwsub.Items.Add(new ExtAspNet.ListItem("普工", "3710"));


            //工作地点
            e = BLL.Bllbase.get_table("[pub_area]");
            ddlSheng.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlSheng.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["svalue"].ToString().Trim(), e.Rows[i]["scode"].ToString().Trim()));
            }
            ddlSheng.DataBind();
            ddlSheng.SelectedIndex = ddlSheng.Items.IndexOf(ddlSheng.Items.FindByValue("1030"));
            ddlShi.Items.Add(new ExtAspNet.ListItem("东莞","103002"));
           

            //镇区
            e = BLL.Bllbase.get_table("[pub_zone]");
            ddlzone.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlzone.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["svalue"].ToString().Trim(), e.Rows[i]["scode"].ToString().Trim()));
            }
            ddlzone.DataBind();

         
            //学历
            e = BLL.Bllbase.get_table("[sys_edu]");
            ddledu.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddledu.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["edu_nm"].ToString().Trim(), e.Rows[i]["edu_nm"].ToString().Trim()));
            }
            ddledu.DataBind();

            date1.Text = DateTime.Now.ToString("yyyy-MM-dd");

            date2.Text = DateTime.Now.AddDays(30).ToString("yyyy-MM-dd");

      }

     protected void ddlSheng_SelectedIndexChanged(object sender, EventArgs e)
     {
         ddlShi.Items.Clear();
         BindShi();
     }

 

     private void BindShi()
     {
         string sheng = ddlSheng.SelectedValue;
         //工作地点
          DataTable  e = BLL.Bllbase.get_table("[pub_area_sub]", "left(scode,4)='"+sheng+"'");
          ddlShi.Items.Clear();
         for (int i = 0; i < e.Rows.Count; i++)
         {
             ddlShi.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["svalue"].ToString().Trim(), e.Rows[i]["scode"].ToString().Trim()));
         }
         ddlShi.DataBind();


       //  ddlShi.Items.Insert(0, new ListItem("选择地区市", "-1"));
     }

     protected void ddlgw_SelectedIndexChanged(object sender, EventArgs e)
     {
         ddlgwsub.Items.Clear();
         BindGW();
     }



     private void BindGW()
     {
         string gw = ddlgw.SelectedValue.Trim();
         gw = gw.Substring(0,2);
         //工作地点
         DataTable e = BLL.Bllbase.get_table("pub_cate_sub", "left(scode,2)='" + gw + "'");
         ddlgwsub.Items.Clear();
         for (int i = 0; i < e.Rows.Count; i++)
         {
             ddlgwsub.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["svalue"].ToString(), e.Rows[i]["scode"].ToString()));
         }
         ddlgwsub.DataBind();
                  //  ddlShi.Items.Insert(0, new ListItem("选择地区市", "-1"));
     }


        protected void btnSubmit_Click(object sender, EventArgs e)
        {
          Model.CO.jobs jb=new Model.CO.jobs();

          jb.jbh = BLL.BllAutoCode.GetMaxBH("comp_job"); //岗位编号
          if (jb.jbh == "") return;

          jb.cbh = ddlcompany.SelectedValue; //公司编号
          jb.cname = ddlcompany.SelectedText; //公司名称

          jb.title = txtjob.Text; //岗位

          jb.cate = ddlgw.SelectedValue; //岗位
          jb.cate_sub = ddlgwsub.SelectedValue; //子岗位


          jb.area = ddlSheng.SelectedValue; //省
          jb.area_sub = ddlShi.SelectedValue; //市
          jb.zone = ddlzone.SelectedValue;

          if (VAN.IsInt(txtjobday.Text))
              jb.jobday = int.Parse(txtjobday.Text);
          else
              jb.jobday = 0;

          if (VAN.IsInt(txtage.Text))
             jb.age = int.Parse(txtage.Text);
          else
              jb.age = 0;

          jb.stdate=DateTime.Parse(date1.Text.Trim());
          jb.edate = DateTime.Parse(date2.Text.Trim());
          jb.sex = ddlsex.SelectedValue;
          jb.keys = txtkey.Text;



          if (txtmoney.Text!="")
              jb.moneys = int.Parse(txtage.Text);
          else
              jb.moneys = 0;


         // jb.moneys =decimal.Parse(txtmoney.Text);

          if (txtnum.Text != "")
              jb.pnum = int.Parse(txtnum.Text);
          else
              jb.pnum = 0;

          //jb.pnum = int.Parse(txtnum.Text);

          jb.edu = ddledu.SelectedValue;



           jb.remarker= HttpUtility.HtmlEncode(FCKeditor1.Value);

            BLL.CO.jobs js = new BLL.CO.jobs();
            js.Add(jb);

            //更新业务员操作记录
            BLL.Bllbase.update_rec(tab, um, " jbh='" + jb.jbh + "' ");


            Alert.Show("添加完成 ");
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }

       
    }
}